package com.itheima.开启多线程.卖票.线程安全问题;

/**
 * @Author 王加鑫
 * @Date 2021/5/22 14:56
 * @Version 1.0
 */
public class Ticket implements Runnable {
    //总共100张票
    private int ticket = 100;

    private String s = "abc";

    @Override
    public void run() {
        while (true){
            if(ticket <= 0){
                break;
            }else {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                ticket--;
                System.out.println(Thread.currentThread().getName() + "正在卖票,还剩下" + ticket + "张票");
            }

        }
    }
}
